package com.bw.zhuangao5___day002.Fragment;


import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bw.mvp.V.BannerFragment;
import com.bw.zhuangao5___day002.Activity.MainActivity;
import com.bw.zhuangao5___day002.Glide.Glides;
import com.bw.zhuangao5___day002.R;
import com.bw.zhuangao5___day002.UI.Login.BlankFragmentLogin;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import io.reactivex.annotations.Nullable;


public class BlankFragmentGames extends BannerFragment {


    private ImageView gamesImg;
    private TextView gamesZhang;
    private TextView gamesMima;
    private Switch switch1;
    private LinearLayout huzhi;
    private Button hangmu;
    private Button huojian;
    private Button junshi;
    private EditText https;
    private Button panduan;
    private ImageView erweimaimg;
    private ImageView saomaimg;

    @Override
    public int bandLayoud() {
        return R.layout.fragment_blank_fragment_games;
    }

    @Override
    public void initView() {
        gamesImg = (ImageView) findViewById(R.id.games_Img);
        gamesZhang = (TextView) findViewById(R.id.games_Zhang);
        gamesMima = (TextView) findViewById(R.id.games_Mima);
        switch1 = (Switch) findViewById(R.id.switch1);
        huzhi = (LinearLayout) findViewById(R.id.huzhi);
        hangmu = (Button) findViewById(R.id.hangmu);
        huojian = (Button) findViewById(R.id.huojian);
        junshi = (Button) findViewById(R.id.junshi);
        https = (EditText) findViewById(R.id.https);
        panduan = (Button) findViewById(R.id.panduan);
        erweimaimg = (ImageView) findViewById(R.id.erweimaimg);
        saomaimg = (ImageView) findViewById(R.id.saomaimg);
    }

    @Override
    public void initDate() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.CAMERA,Manifest.permission.VIBRATE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 200);
        }
        switch1.setChecked(false);
        switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    MainActivity.bian.setBackgroundColor(Color.YELLOW);
                } else {
                    MainActivity.bian.setBackgroundColor(Color.WHITE);
                }
            }
        });
        Glides.Yuanjiao(getActivity(), R.mipmap.kotlin1, gamesImg, 50);

        gamesZhang.setText("当前车型是：" + BlankFragmentLogin.BlankFragmentLoginEditText1.getText().toString());
        gamesMima.setText("当前车牌号是：" + BlankFragmentLogin.BlankFragmentLoginEditText2.getText().toString());


        panduan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /////////网络测试
                NetworkUtils.NetworkType networkType = NetworkUtils.getNetworkType();
                ToastUtils.showShort(networkType + "");
            }
        });
        hangmu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                startActivity(intent);
            }
        });

        huojian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("android.media.action.IMAGE_CAPTURE");
                intent.addCategory("android.intent.category.DEFAULT");
                startActivity(intent);
            }
        });

        junshi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //打开使用系统浏览器打开一个网址

                String string = https.getText().toString();
                if (!TextUtils.isEmpty(string)) {
                    //设置数据
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("" + string));
                    startActivity(intent);
                } else {
                    ToastUtils.showShort("数据不能为空");
                }

            }
        });


        erweimaimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouter.getInstance().build("/asd/ccc").navigation();
            }
        });


        saomaimg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
          sao();
            }
        });





    }

    //扫描二维码
    private void sao() {
        Intent intent = new Intent(getActivity(), CaptureActivity.class);
        startActivityForResult(intent,101);
    }
    //处理结果
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 101 && resultCode == Activity.RESULT_OK &&data != null){
            Bundle bundle = data.getExtras();
            if(bundle == null){
                return;
            }
            if(bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS){
                String string = bundle.getString(CodeUtils.RESULT_STRING);
                Toast.makeText(getActivity(), "扫描结果"+string, Toast.LENGTH_SHORT).show();
            }
        }
    }



}
